#encoding:utf-8
#===Gps传输对象
class Gps
  #[vehicle_no] 车号
  #[lng] 经度
	#[lat] 纬度
	#[speed] 速度
	#[stop_time] 停车时间
  #[direction] 方向
  attr_accessor :vehicle_no, :lng, :lat, :speed, :stop_time, :direction, :bl_no, :datetime

  def update(hash)
    puts "_____________________-#{hash}"
    self.lng = hash[:lng] if hash[:lng]
    self.lat = hash[:lat] if hash[:lat]
    self.bl_no = hash[:bl_no] if hash[:bl_no]
    self.speed = hash[:speed] if hash[:speed]
    self.datetime = hash[:datetime] if hash[:datetime]
    self.stop_time = hash[:stop_time] if hash[:stop_time]
    self.direction = hash[:direction] if hash[:direction]
    self.vehicle_no = hash[:vehicle_no] if hash[:vehicle_no]
  end

  #根据车号数组查询最近一两分钟的历史gps数据
  def self.gps_resent_vehicles(vehicle_no_arr)
    gps_arr = []
    gps_histories = GpsHistory.recent_histories_vehicles vehicle_no_arr
    gps_histories.each {|g_h| gps_arr << Gps.gps_from_history(g_h) }
    gps_arr
  end

  private
  #从GpsHistory对象构造一个Gps对象
  def self.gps_from_history(history)
    gps = Gps.new
    gps.lng = history.longitude
    gps.lat = history.latitude
    gps.vehicle_no = history.vehicle_no
    gps
  end
end